/*
 * PanzerConsole.cpp
 *
 *  Created on: 16/02/2009
 *      Author: rodrigo
 *      Description: this CPP file holds all the main events for this chess engine.
 *      Since it uses the UCI protocol
 *
 *		Changelog: Fraga
 *					- Added main Loop
 *					- Added includes
 *					- Added some features to console interaction
 *
 *
 */

#include <iostream>
#include <string>
#include <vector>

//function prototype declared within UCIConsole
#include "header/PanzerConsole.h"
#include "header/Engine.h"

using namespace::std;

//main here receives some arguments, maybe we can use it later on preloadFunction, whatever
int main(int argc, char * argv[]) {

	//some local variables to hold exit status and inputs
	string inputCommand;
	int exitStatus = 0;
	Engine engine;

	//Loads the engine and main methods
	cout << "loading Panzer Chess Engine...\n";
	preLoadFunction();
	cout << "ready.\n";



	//this is the UCI console main loop. Here we interact with our search engine.
	//The main purpose is to act as a layer between GUI and the search algorithm
	do
	{
		//console and opens the input stream for user input (or UCI GUI input)
		//cout << "PanzerConsole> ";
		//TODO: improve here. Sometimes the GUI can send complex commands like: set position <a> <b> etc...
		getline(cin, inputCommand);

		//cout << "Input command was: " << inputCommand << endl;

		// Starts the engine
		engine.ReadCommand(inputCommand);
		//engine.PrintCurrentCommands();


		/*
		//here we should load the engine
		if(inputCommand == "go") {
			cout << "go selected. Loading engine...\n";
		}

		//here we should print all help message
		if(inputCommand == "help") {
			cout << "Help selected. Print all possible commands\n";
		}

		//here we should exit
		if(inputCommand == "exit") {
			cout << "exiting...\n";
			exitStatus = EXIT_SUCCESS;
		}

		//here we should set engine debug mode on
		if(inputCommand == "debug on") {
			cout << "setting debug mode on...\n";
		}

		//here we should set engine debug mode on
		if(inputCommand == "debug off") {
			cout << "setting debug mode off...\n";
		}

		if(inputCommand == "isready") {
			cout << "is ready?...\n";
		}
		*/

	}while(inputCommand != "quit" && exitStatus == 0);

	//PostExitFunction
	postExitFunction();

	//return exitStatus
	return exitStatus;

}

//implements preloadfunction declared within PanzerConsole.h
void preLoadFunction() {
	//do something like:
	//Engine e = new Engine();
	//e.setHashTableSize(size);
	//e.load();
	//e.setReady();
}

//implements postExitFunction declared within PanzerConsole.h
void postExitFunction() {
	//do something
	//e.freeMem();
	//e.unload();

}
